package com.zllkj.mm;

import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.StrictMode;

import androidx.multidex.MultiDexApplication;

import com.orhanobut.hawk.Hawk;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import com.previewlibrary.ZoomMediaLoader;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshFooter;
import com.scwang.smart.refresh.layout.api.RefreshHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator;
import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.zllkj.mm.common.ClientConfig;
import com.zllkj.mm.util.NinePictureImageLoader;

public class MyApp extends MultiDexApplication/*CaiBaChatApp*/ {

    private static MyApp instance;
    private static Handler mHandler;//主线程Handler
    public static String wxAppId = "wx0f3a60f7ae964850";



    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        mHandler = new Handler();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
        Hawk.init(this).build();
        // 初始化SDK
        UMConfigure.init(this, ClientConfig.UMEG_APPKEY, "Umeng", UMConfigure.DEVICE_TYPE_PHONE, null);
        // 选用AUTO页面采集模式
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
        Logger.addLogAdapter(new AndroidLogAdapter());
        final IWXAPI api = WXAPIFactory.createWXAPI(this, null,false);

        api.registerApp(wxAppId);
        ZoomMediaLoader.getInstance().init(new NinePictureImageLoader());


    }

    //static 代码段可以防止内存泄露
    static {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.black);//全局设置主题颜色
                return new ClassicsHeader(context);//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter
                return new ClassicsFooter(context).setDrawableSize(20);
            }
        });
    }

    /**
     * 获得当前app运行的ApplicationContext
     *
     * @return
     */
    public static MyApp getInstance() {
        // 因为我们程序运行后,Application是首先初始化的,如果在这里不用判断instance是否为空
        return instance;
    }

    public static MyApp getContext() {
        // 因为我们程序运行后,Application是首先初始化的,如果在这里不用判断instance是否为空
        return instance;
    }

    public String getSessionId() {
//        return AccountModel.getInstance().getSessionId();
        return "";
    }

}